package com.jnshu.controller;

import com.jnshu.dto.message.MessageListBackList;
import com.jnshu.dto.message.MessageListDetailDto;
import com.jnshu.dto.message.MessageVo;
import com.jnshu.service.MessageService;
import com.jnshu.tools.HeadUtil;
import com.jnshu.tools.resultUtils.PageBean;
import com.jnshu.tools.resultUtils.RUtil;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @Author xmp
 * @Description 消息管理
 * @Date 0:18 2019/7/31
 **/
@RestController
@Log
public class AdminMessageController {
    @Autowired(required = false)
    MessageService messageService;

    @Autowired(required = false)
    HeadUtil headUtil;


    /**
     * 消息列表
     * @param messageListBackList
     * @return
     */
    @PostMapping("/message/list/")
    public PageBean messageList(@RequestBody MessageListBackList messageListBackList) {
        log.info("消息列表的入参为："+messageListBackList);
        return messageService.selectMessageList(messageListBackList);
    }

    @GetMapping("/message/list")
    public PageBean message(@RequestParam(name = "pageNum",defaultValue = "1")int pageNum,
                            @RequestParam(name = "pageSize",defaultValue = "10")int pageSize){
        log.info("消息列表的入参为:"+pageNum+","+pageSize);
        return messageService.selectMessage(pageNum,pageSize);
    }

    /**
     * 消息详情
     * @param id
     * @return
     */
    @GetMapping("/message")
    public ResultBean getMessage(long id) {
        log.info("消息详情页面的入参为："+id);
        MessageListDetailDto messageListDetailDto = messageService.selectMessageById(id);
        return RUtil.ok(messageListDetailDto);
    }

    /**
     * 消息编辑
     * @param messageVo
     * @return
     */
    @PutMapping("/message")
    public ResultBean putMessage(MessageVo messageVo) {
        log.info("消息编辑页面的入参为："+messageVo);
        return messageService.updateMessage(messageVo);
    }


    /**
     * 消息新增
     * @param messageVo
     * @return
     */
    @PostMapping("/message")
    public ResultBean postMessage(MessageVo messageVo) throws ParseException, SchedulerException {
        log.info("消息新增页面的入参为："+messageVo);
        return messageService.insertMessage(messageVo);
    }

    /**
     * 消息删除
     * @param id
     * @return
     */
    @DeleteMapping("/message")
    public ResultBean deleteMessage(@RequestParam long id) {
        log.info("页面消息删除传入的ID："+id);
        return messageService.deleteMessage(id);
    }

    /**
     * 修改公告上下架状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/message/status")
    public ResultBean putMessageStatus(long id, int status){
        log.info("要修改上下架状态的公告ID为："+id+",公告上下架的状态："+status);
        return messageService.updateMessageStatus(id,status);
    }
}
